package com.problem.leetcode;

/**
 * @author didi
 * @DESCRIPTION
 * @create 2019-04-26 14:17
 **/

public class Problem203 {
    public ListNode removeElements(ListNode head, int val) {
        ListNode tmpHeade = new ListNode(-1), currentIndex = tmpHeade, nextIndex = head;
        tmpHeade.next = head;

        while (nextIndex != null) {
            if (nextIndex.val == val) {
                currentIndex.next = nextIndex.next;
                nextIndex.next = null;
                nextIndex = currentIndex.next;
            }else {
                currentIndex = nextIndex;
                nextIndex = nextIndex.next;
            }

        }

        return tmpHeade.next;

    }
}
